﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Oragon.Architecture.Data.SqlBuilder
{
	/// <summary>
	/// Representa um ítem da cláusula from do SQL
	/// </summary>
	[Serializable]
	public class FromItem : ISQLStatement
	{

        public ISQLStatement Expression { get; private set; }
		
		public string Alias { get; set; }

		public FromItem(){}

        public FromItem(ISQLStatement expression)
            : this(expression, null)
		{
			
		}
		
		/// <summary>
		/// Cria um FromItem
		/// </summary>
		/// <param name="Expression"></param>
		/// <param name="Alias"></param>
		public FromItem(ISQLStatement expression, string alias )
		{
			this.Expression = expression;
			this.Alias = alias;
		}

		
		/// <summary>
		/// Retorna o SQL referente ao segmento
		/// </summary>
		/// <returns></returns>
		public string ToSQL()
		{
			if (this.Alias == null)
				return this.Expression.ToSQL();
			else
				return string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} as {1}", this.Expression.ToSQL(), this.Alias);
		}
	}
}
